package river_city_ransom.implementations;

import java.util.ArrayList;
import java.util.List;

import exceptions.ComposantError;
import river_city_ransom.services.Dimensions;
import river_city_ransom.services.Objet;
import river_city_ransom.services.PersonnageJouable;
import tools.Toolbox;


public class PersonnageJouable_I extends Personnage_I implements PersonnageJouable {
	protected int sommeDArgent;
	protected List<Objet> poche;
	
	public PersonnageJouable_I(String n, Dimensions d, int f, int pv) {
		super();
		try {
			init(n, d, f, pv);
		}
		catch(ComposantError e) {
			System.err.println(e.getMessage());
		}
	}
	
	@Override
	public boolean equals(Object o) {
		if(!(o instanceof PersonnageJouable)) {
			return false;
		}
		if(!super.equals(o)) {
			return false;
		}
		if(sommeDArgent() != ((PersonnageJouable) o).sommeDArgent()) {
			return false;
		}
		if(!Toolbox.equals(poche(), ((PersonnageJouable) o).poche())) {
			return false;
		}
		
		return true;
	}
	
	/** ________________________________________________________ CONSTRUCTORS */
	@Override
	public void init(String n, Dimensions d, int f, int pv) throws ComposantError {
		// Equipable
		dimensions = d;
		estEquipable = false;
		estPorte = false;
		estJete = 0;
		position = new Position_I(0, 0, 0);
		// Personnage
		nom = n;
		force = f;
		maxPointsDeVie = pv;
		pointsDeVie = pv;
		estVaincu = false;
		choseEquipee = null;
		estEquipe = false;
		versLaDroite = true;
		estGele = 0;
		// PersonnageJouable
		sommeDArgent = 0;
		poche = new ArrayList<Objet>();
	}

	/** _________________________________________________________ OBSERVATORS */
	@Override
	public int sommeDArgent() {
		return sommeDArgent;
	}

	@Override
	public List<Objet> poche() {
		return poche;
	}

	/** ___________________________________________________________ OPERATORS */
	@Override
	public void deposerArgent(int a) throws ComposantError {
		sommeDArgent += a;
	}

	@Override
	public void retirerArgent(int a) throws ComposantError {
		sommeDArgent -= a;
	}

	@Override
	public void ranger(Objet o) throws ComposantError {
		poche.add(o);
	}

	@Override
	public void vendre(Objet o) throws ComposantError {
		poche.remove(o);
		sommeDArgent += o.valeur();
	}
}
